﻿using UnityEngine;
using System.Collections;

namespace FrameWork
{
    /// <summary>
    /// monobehaviour 的单例继承类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class DDOLSingleton<T> : MonoBehaviour where T : Component //会添加到物体上
    {
        protected static T _instance;

        public static T Instance
        {
            get
            {
                if (null == _instance)
                {
                    GameObject go = GameObject.Find("DDOLGameObject");
                    if (null == go)
                    {
                        go = new GameObject("DDOLGameObject");
                        DontDestroyOnLoad(go);
                    }
                    _instance = go.AddComponent<T>();
                   
                }
                return _instance;
            }

        }

        private void OnApplicationQuit()
        {
            _instance = null;
        }

    }

}
